#ifndef __AUDIO_H__
#define __AUDIO_H__

#include <string>
#include <SDL.h>

typedef enum
{
  Accent = 0,
  Quarter,
  Eight,
  Sixteen,
  Triplet,
  Master
} Volume;

class AudioWAV
{
public:
  AudioWAV (const std::string &file);
  ~AudioWAV ();

  const SDL_AudioSpec & get_spec () const;
  unsigned int get_len () const;
  unsigned int copy_to_buffer (unsigned char *buffer, unsigned int num);

  /* Returns true if an error has occurred */
  bool operator! () const;
  const unsigned char & operator[] (unsigned int idx) const;

private:
  bool error;
  SDL_AudioSpec _spec;
  unsigned char *_buffer;
  unsigned int _buffer_len;
  unsigned int _pos;
};

class AudioParams
{
public:
  AudioParams (const std::string &wav_file);
  AudioParams (const std::string &wav_file,
               const SDL_AudioSpec &spec);

  void set_volume (Volume type, int value);
  void set_bpm (int bpm);
  void set_beats (int beats);
  void set_spec (const SDL_AudioSpec &spec);
  int get_volume (Volume type) const;
  int get_bpm () const;
  int get_beats () const;
  const SDL_AudioSpec & get_spec () const;
  const AudioWAV & get_audio_wav () const;
  void read_settings (const std::string &file);
  void write_settings (const std::string &file);

private:
  int _bpm;
  int _beats;
  int _accent_vol;
  int _quarter_vol;
  int _eight_vol;
  int _sixteen_vol;
  int _triplet_vol;
  int _master_vol;
  AudioWAV _tap;
  SDL_AudioSpec _spec;
};

void audio_callback (void *data, unsigned char *stream, int len);

#endif
